package response

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"xinxiang-mutual-platform/model/common"
)

type Response struct {
	Code int         `json:"code"`
	Data interface{} `json:"data"`
	Msg  string      `json:"msg"`
}

func Result(code int, data interface{}, msg string, c *gin.Context) {
	c.JSON(http.StatusOK, Response{
		code,
		data,
		msg,
	})
}

func OK(c *gin.Context) {
	Result(common.SUCCESS, map[string]interface{}{}, common.CodeMsg[common.SUCCESS], c)
}
func OKWithDitals(code int, data interface{}, c *gin.Context) {
	Result(code, data, common.CodeMsg[code], c)
}
func Fail(c *gin.Context) {
	Result(common.ERROR, map[string]interface{}{}, common.CodeMsg[common.ERROR], c)
}
func FailWithDitals(code int, c *gin.Context) {
	Result(code, nil, common.CodeMsg[code], c)
}
